<!doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" Content="text/html; charset=utf-8"/>

	<link rel="stylesheet" type="text/css" href="../css/header.css">
	<link rel="stylesheet" type="text/css" href="../css/footer.css">
	<link rel="stylesheet" type="text/css" href="../css/QnA_board.css">
	<link rel="stylesheet" type="text/css" href="../css/QnA_board_edit.css">
	<link rel="stylesheet" href="../res/bootstrap/css/bootstrap.min.css">
	<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.js"></script>
	<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/jquery-ui.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
	<script type="text/javascript" src="../js/QnA_board_edit.js"></script>
	<script type="text/javascript" src="../se2/js/HuskyEZCreator.js"></script>
	<script src="../myUtil.js"></script>
<script>
  var oEditors = [];
  
  $(function() {
    nhn.husky.EZCreator.createInIFrame({
      oAppRef: oEditors,
      elPlaceHolder: "textarea1",
      sSkinURI: "../se2/SmartEditor2Skin.html",        
      fCreator: "createSEditor2"
 
    
  });
  })
    var myModule = angular.module('myModule', []);

    myModule.controller('MyController', function ($scope, $http,$location) {
        $scope.items = [];
        $scope.subjectItems=[];
        $scope.user={};
        $scope.subject={};
        
        $scope.write = function(){
        	oEditors.getById["textarea1"].exec("UPDATE_CONTENTS_FIELD", []);
        	var con = $('#textarea1').val();
        	
        	if($location.search().content_id!=null){
        		myUtil.onHttp($http,'post','modify.do',null,{content_id:$location.search().content_id,title:$scope.title,content:con,notice:($scope.user.authority=="ROLE_ADMIN" ? 1 : 0),subject_id:''},function(data){alert(data); location.href="QnA.html";});
        	}
        	else{
        		myUtil.onHttp($http, 'post', 'write.do', null, {board_id:2 ,title:$scope.title , content:con,notice:($scope.user.authority=="ROLE_ADMIN" ? 1 : 0) ,hit:0 , id:$scope.user.id ,subject_id:''}, function(data){alert(data); location.href="QnA.html";});
        	}
        }
        
        $scope.loadData = function() {
        		if($location.search().content_id!=null){
        			
            		myUtil.onHttp($http,'get','content.do',{content_id:$location.search().content_id},null,function(data) {

            			
            			$scope.content=data.content.content;
            			$scope.title=data.content.title;
            		});
            	};
        }
        
        $scope.loadUser = function(){
        	myUtil.onHttp($http, 'get', 'userAuthority.do', null, null, function(data){
        		$scope.user=data;
        		
        		
        		$scope.dis= ($scope.user.authority=="ROLE_ADMIN" ? "QnA게시판에 새로운 공지등록" : "QnA새로운 질문등록");
        		
        		
        	})
        }

        $scope.loadUser();
        $scope.loadData();
        
       
    });
   
</script>
<script> 
    $(function(){
      $(".header").load("header.html");$(".footer").load("footer.html"); 
    });
</script> 

</head>
<body ng-app="myModule">
<div class="container" ng-controller="MyController">
<!-- header-->
<div class="header span12">
</div>

<!--notice_content-->
<h1>QnA</h1> <span>{{dis}}</span>
<br/>
<form ng-submit="write()">

	
	<br/><div class="span2">제목 </div><input ng-model="title" name="title" id="notice_name" type="text"/>
	<br/><div class="span2">파일 첨부 </div><button type="button" class="btn btn-info" onclick="notice_file_add()">파일추가</button>
	<div id="file_add"></div><!--추가되는 파일 이름과 id는 notice_file-->
	
	<textarea name="notice_content" id="textarea1" ng-model="content" class="span11 notice_content"></textarea>
	
	
	<div class="button"><input type="submit" class="btn btn-primary" value="등록">&nbsp;&nbsp;<a class="btn" href="">취소</a></div>
</form>
<!--//notice_content-->

<!--footer-->
	
	<div class="footer span12"></div>
<!--//footer-->
</div>
</body>
</html>